﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using Cn.Edwon.Biz;
using Cn.Edwon.Spring;
using Cn.Cellula.Model.Content;

namespace Cn.Cellula.Website.Admin.Content.Vote {
    public partial class VoteLog : PageSupport{
        IBiz biz = BizFactory.Get<IBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                InitForm();
            }
            LoadVoteLog();
        }
        private void InitForm() {
            this.ddl_Vote.DataSource = biz.LoadAll<TVoteEO>();
            this.ddl_Vote.DataTextField = "VoteTitle";
            this.ddl_Vote.DataValueField = "VoteKey";
            this.ddl_Vote.DataBind();

            try {
                this.ddl_Vote.SelectedValue = Request.QueryString["id"];
            } catch { }
        }
        private void LoadVoteLog() {
            String hql = "from VVoteLogEO eo where eo.VoteKey='"+this.ddl_Vote.SelectedValue+"' ";
            if (!String.IsNullOrEmpty(this.txt_UserName.Text)) {
                hql += " and eo.Operator like '" + this.txt_UserName.Text + "' ";
            }
            if (!String.IsNullOrEmpty(this.txt_IP.Text)) {
                hql += " and eo.FromIp like '" + this.txt_IP.Text + "' ";
            }
            hql += " order by eo.VoteDate desc ";
            this.gvList.DataSource = biz.Find<VVoteLogEO>(hql);
            this.gvList.DataBind();
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e) {
            gvList.PageIndex = e.NewPageIndex;
            LoadVoteLog();
        }
    }
}
